package cn.tedu.review;

import java.security.PublicKey;

/*本类用于负此方法的重写
* 重写的规则：
* 两同:方法名与参数列表
* 两小：返回值类型 <=
* 一大：修饰符 >=*/
public class TestExtends {
    public static void main(String[] args) {
        Father f = new Father();
        Son s = new Son();
        f.eat();
        s.eat();
        f.sleep(6);
        s.sleep(9);
        int a=f.play();
        System.out.println("父类"+a);
        int b =s.play();
        System.out.println("子类"+b);

        Animal a2 = f.getPet();
        System.out.println(a2.name);
        Dog d2 = s.getPet();
        System.out.println(d2.name);
    }
}
class Father{
    public void eat(){
        System.out.println("爸爸爱吃肉");
    }
    public void sleep(int n){
        System.out.println("爸爸晚上睡"+n+"个小时");
    }
    public int play(){
        System.out.println("爸爸在玩电脑");
        return  666;
    }

    public Animal getPet (){
        Animal a =new Animal();
        return a ;
    }
}
class Son extends Father{
    @Override
    public void eat(){
        System.out.println("儿子爱蔬菜");
    }
    @Override
    public void sleep(int n){
        System.out.println("儿子晚上睡"+n+"个小时");
    }
    @Override
    public int play(){
        System.out.println("儿子在拆电视");
        return  888;
    }
/*    public Animal getPet(){*/
/*        Animal a = new Animal();*/
/*        return a;*/
/*    }*/
    public Dog getPet(){
        Dog d = new Dog();
        return d;
    }
}
//辅助测试的类
class Animal{
    {
        System.out.println("构造代码块");
    }
    static {
        System.out.println("静态代码块");
    }
    String name = "啥都行";
}
class Dog extends Animal{
    String name  ="吃那么快";
}